package com.woniuxy.woniuticket.usermodule.utils;

import sun.security.provider.MD5;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author ZYF
 * @Description:TODO
 * @date 2019/6/17
 * @Version 1.0
 */

public class GetMd5 {
    public static void main(String[] args) {
        System.out.println(makeMd5("123456"));
        //E1AADC3949BA59ABBE56E057F2AF883E
    }

    public static String makeMd5(String pas) {
        MessageDigest md5 = null;
        if (pas != null) {
            try {
                md5 = MessageDigest.getInstance("MD5");

            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            byte[] results = md5.digest(pas.getBytes());
            //将得到的字节数组变成字符串返回
            String pwd2 = "";
            for (byte i : results) {
                String s = Integer.toHexString(i & 0xff);
                if (s.length() == 1) {
                    s = "a" + s; //具体怎么个补法，程序员可以自己随意变化，这就是变种
                }
                pwd2 += s;
            }
            pwd2 = pwd2.toUpperCase();
            return pwd2;
        } else {
            return "密码为空";
        }

    }
}
